home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / sun4.md / gdb / RCS / infrun.c,v < prev    next >
Encoding:
Text File  |  1992-06-24  |  58.0 KB  |  1,979 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     92.06.09.14.26.46;  author secor;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* Start (run) and stop the inferior process, for GDB.
  26.    Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  27.  
  28. This file is part of GDB.
  29.  
  30. This program is free software; you can redistribute it and/or modify
  31. it under the terms of the GNU General Public License as published by
  32. the Free Software Foundation; either version 2 of the License, or
  33. (at your option) any later version.
  34.  
  35. This program is distributed in the hope that it will be useful,
  36. but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38. GNU General Public License for more details.
  39.  
  40. You should have received a copy of the GNU General Public License
  41. along with this program; if not, write to the Free Software
  42. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  43.  
  44. /* Notes on the algorithm used in wait_for_inferior to determine if we
  45.    just did a subroutine call when stepping.  We have the following
  46.    information at that point:
  47.  
  48.                   Current and previous (just before this step) pc.
  49.           Current and previous sp.
  50.           Current and previous start of current function.
  51.  
  52.    If the starts of the functions don't match, then
  53.  
  54.        a) We did a subroutine call.
  55.  
  56.    In this case, the pc will be at the beginning of a function.
  57.  
  58.     b) We did a subroutine return.
  59.  
  60.    Otherwise.
  61.  
  62.     c) We did a longjmp.
  63.  
  64.    If we did a longjump, we were doing "nexti", since a next would
  65.    have attempted to skip over the assembly language routine in which
  66.    the longjmp is coded and would have simply been the equivalent of a
  67.    continue.  I consider this ok behaivior.  We'd like one of two
  68.    things to happen if we are doing a nexti through the longjmp()
  69.    routine: 1) It behaves as a stepi, or 2) It acts like a continue as
  70.    above.  Given that this is a special case, and that anybody who
  71.    thinks that the concept of sub calls is meaningful in the context
  72.    of a longjmp, I'll take either one.  Let's see what happens.  
  73.  
  74.    Acts like a subroutine return.  I can handle that with no problem
  75.    at all.
  76.  
  77.    -->So: If the current and previous beginnings of the current
  78.    function don't match, *and* the pc is at the start of a function,
  79.    we've done a subroutine call.  If the pc is not at the start of a
  80.    function, we *didn't* do a subroutine call.  
  81.  
  82.    -->If the beginnings of the current and previous function do match,
  83.    either: 
  84.  
  85.        a) We just did a recursive call.
  86.  
  87.        In this case, we would be at the very beginning of a
  88.        function and 1) it will have a prologue (don't jump to
  89.        before prologue, or 2) (we assume here that it doesn't have
  90.        a prologue) there will have been a change in the stack
  91.        pointer over the last instruction.  (Ie. it's got to put
  92.        the saved pc somewhere.  The stack is the usual place.  In
  93.        a recursive call a register is only an option if there's a
  94.        prologue to do something with it.  This is even true on
  95.        register window machines; the prologue sets up the new
  96.        window.  It might not be true on a register window machine
  97.        where the call instruction moved the register window
  98.        itself.  Hmmm.  One would hope that the stack pointer would
  99.        also change.  If it doesn't, somebody send me a note, and
  100.        I'll work out a more general theory.
  101.        bug-gdb@@prep.ai.mit.edu).  This is true (albeit slipperly
  102.        so) on all machines I'm aware of:
  103.  
  104.           m68k:    Call changes stack pointer.  Regular jumps don't.
  105.  
  106.           sparc:    Recursive calls must have frames and therefor,
  107.                     prologues.
  108.  
  109.           vax:    All calls have frames and hence change the
  110.                     stack pointer.
  111.  
  112.     b) We did a return from a recursive call.  I don't see that we
  113.        have either the ability or the need to distinguish this
  114.        from an ordinary jump.  The stack frame will be printed
  115.        when and if the frame pointer changes; if we are in a
  116.        function without a frame pointer, it's the users own
  117.        lookout.
  118.  
  119.     c) We did a jump within a function.  We assume that this is
  120.        true if we didn't do a recursive call.
  121.  
  122.     d) We are in no-man's land ("I see no symbols here").  We
  123.        don't worry about this; it will make calls look like simple
  124.        jumps (and the stack frames will be printed when the frame
  125.        pointer moves), which is a reasonably non-violent response.
  126. */
  127.  
  128. #include "defs.h"
  129. #include <string.h>
  130. #include "symtab.h"
  131. #include "frame.h"
  132. #include "inferior.h"
  133. #include "breakpoint.h"
  134. #include "wait.h"
  135. #include "gdbcore.h"
  136. #include "signame.h"
  137. #include "command.h"
  138. #include "terminal.h"        /* For #ifdef TIOCGPGRP and new_tty */
  139. #include "target.h"
  140.  
  141. #include <signal.h>
  142.  
  143. /* unistd.h is needed to #define X_OK */
  144. #ifdef USG
  145. #include <unistd.h>
  146. #else
  147. #include <sys/file.h>
  148. #endif
  149.  
  150. #ifdef SET_STACK_LIMIT_HUGE
  151. #include <sys/time.h>
  152. #include <sys/resource.h>
  153.  
  154. extern int original_stack_limit;
  155. #endif /* SET_STACK_LIMIT_HUGE */
  156.  
  157. /* Prototypes for local functions */
  158.  
  159. static void
  160. signals_info PARAMS ((char *, int));
  161.  
  162. static void
  163. handle_command PARAMS ((char *, int));
  164.  
  165. static void
  166. sig_print_info PARAMS ((int));
  167.  
  168. static void
  169. sig_print_header PARAMS ((void));
  170.  
  171. static void
  172. remove_step_breakpoint PARAMS ((void));
  173.  
  174. static void
  175. insert_step_breakpoint PARAMS ((void));
  176.  
  177. static void
  178. resume PARAMS ((int, int));
  179.  
  180. static void
  181. resume_cleanups PARAMS ((int));
  182.  
  183. extern char **environ;
  184.  
  185. extern int sys_nerr;
  186. extern char *sys_errlist[];
  187.  
  188. extern struct target_ops child_ops;    /* In inftarg.c */
  189.  
  190. /* Sigtramp is a routine that the kernel calls (which then calls the
  191.    signal handler).  On most machines it is a library routine that
  192.    is linked into the executable.
  193.  
  194.    This macro, given a program counter value and the name of the
  195.    function in which that PC resides (which can be null if the
  196.    name is not known), returns nonzero if the PC and name show
  197.    that we are in sigtramp.
  198.  
  199.    On most machines just see if the name is sigtramp (and if we have
  200.    no name, assume we are not in sigtramp).  */
  201. #if !defined (IN_SIGTRAMP)
  202. #define IN_SIGTRAMP(pc, name) \
  203.   (name && !strcmp ("_sigtramp", name))
  204. #endif
  205.  
  206. /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
  207.    program.  It needs to examine the jmp_buf argument and extract the PC
  208.    from it.  The return value is non-zero on success, zero otherwise. */
  209. #ifndef GET_LONGJMP_TARGET
  210. #define GET_LONGJMP_TARGET(PC_ADDR) 0
  211. #endif
  212.  
  213.  
  214. /* Some machines have trampoline code that sits between function callers
  215.    and the actual functions themselves.  If this machine doesn't have
  216.    such things, disable their processing.  */
  217. #ifndef SKIP_TRAMPOLINE_CODE
  218. #define    SKIP_TRAMPOLINE_CODE(pc)    0
  219. #endif
  220.  
  221. /* For SVR4 shared libraries, each call goes through a small piece of
  222.    trampoline code in the ".init" section.  IN_SOLIB_TRAMPOLINE evaluates
  223.    to nonzero if we are current stopped in one of these. */
  224. #ifndef IN_SOLIB_TRAMPOLINE
  225. #define IN_SOLIB_TRAMPOLINE(pc,name)    0
  226. #endif
  227.  
  228. /* Notify other parts of gdb that might care that signal handling may
  229.    have changed for one or more signals. */
  230. #ifndef NOTICE_SIGNAL_HANDLING_CHANGE
  231. #define NOTICE_SIGNAL_HANDLING_CHANGE    /* No actions */
  232. #endif
  233.  
  234. #ifdef TDESC
  235. #include "tdesc.h"
  236. int safe_to_init_tdesc_context = 0;
  237. extern dc_dcontext_t current_context;
  238. #endif
  239.  
  240. /* Tables of how to react to signals; the user sets them.  */
  241.  
  242. static char signal_stop[NSIG];
  243. static char signal_print[NSIG];
  244. static char signal_program[NSIG];
  245.  
  246. /* Nonzero if breakpoints are now inserted in the inferior.  */
  247. /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
  248.  
  249. /*static*/ int breakpoints_inserted;
  250.  
  251. /* Function inferior was in as of last step command.  */
  252.  
  253. static struct symbol *step_start_function;
  254.  
  255. /* Nonzero => address for special breakpoint for resuming stepping.  */
  256.  
  257. static CORE_ADDR step_resume_break_address;
  258.  
  259. /* Pointer to orig contents of the byte where the special breakpoint is.  */
  260.  
  261. static char step_resume_break_shadow[BREAKPOINT_MAX];
  262.  
  263. /* Nonzero means the special breakpoint is a duplicate
  264.    so it has not itself been inserted.  */
  265.  
  266. static int step_resume_break_duplicate;
  267.  
  268. /* Nonzero if we are expecting a trace trap and should proceed from it.  */
  269.  
  270. static int trap_expected;
  271.  
  272. /* Nonzero if the next time we try to continue the inferior, it will
  273.    step one instruction and generate a spurious trace trap.
  274.    This is used to compensate for a bug in HP-UX.  */
  275.  
  276. static int trap_expected_after_continue;
  277.  
  278. /* Nonzero means expecting a trace trap
  279.    and should stop the inferior and return silently when it happens.  */
  280.  
  281. int stop_after_trap;
  282.  
  283. /* Nonzero means expecting a trap and caller will handle it themselves.
  284.    It is used after attach, due to attaching to a process;
  285.    when running in the shell before the child program has been exec'd;
  286.    and when running some kinds of remote stuff (FIXME?).  */
  287.  
  288. int stop_soon_quietly;
  289.  
  290. /* Nonzero if pc has been changed by the debugger
  291.    since the inferior stopped.  */
  292.  
  293. int pc_changed;
  294.  
  295. /* Nonzero if proceed is being used for a "finish" command or a similar
  296.    situation when stop_registers should be saved.  */
  297.  
  298. int proceed_to_finish;
  299.  
  300. /* Save register contents here when about to pop a stack dummy frame,
  301.    if-and-only-if proceed_to_finish is set.
  302.    Thus this contains the return value from the called function (assuming
  303.    values are returned in a register).  */
  304.  
  305. char stop_registers[REGISTER_BYTES];
  306.  
  307. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  308.  
  309. static int breakpoints_failed;
  310.  
  311. /* Nonzero after stop if current stack frame should be printed.  */
  312.  
  313. static int stop_print_frame;
  314.  
  315. #ifdef NO_SINGLE_STEP
  316. extern int one_stepped;        /* From machine dependent code */
  317. extern void single_step ();    /* Same. */
  318. #endif /* NO_SINGLE_STEP */
  319.  
  320.  
  321. /* Things to clean up if we QUIT out of resume ().  */
  322. /* ARGSUSED */
  323. static void
  324. resume_cleanups (arg)
  325.      int arg;
  326. {
  327.   normal_stop ();
  328. }
  329.  
  330. /* Resume the inferior, but allow a QUIT.  This is useful if the user
  331.    wants to interrupt some lengthy single-stepping operation
  332.    (for child processes, the SIGINT goes to the inferior, and so
  333.    we get a SIGINT random_signal, but for remote debugging and perhaps
  334.    other targets, that's not true).
  335.  
  336.    STEP nonzero if we should step (zero to continue instead).
  337.    SIG is the signal to give the inferior (zero for none).  */
  338. static void
  339. resume (step, sig)
  340.      int step;
  341.      int sig;
  342. {
  343.   struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
  344.   QUIT;
  345.  
  346. #ifdef NO_SINGLE_STEP
  347.   if (step) {
  348.     single_step(sig);    /* Do it the hard way, w/temp breakpoints */
  349.     step = 0;        /* ...and don't ask hardware to do it.  */
  350.   }
  351. #endif
  352.  
  353.   /* Handle any optimized stores to the inferior NOW...  */
  354. #ifdef DO_DEFERRED_STORES
  355.   DO_DEFERRED_STORES;
  356. #endif
  357.  
  358.   target_resume (step, sig);
  359.   discard_cleanups (old_cleanups);
  360. }
  361.  
  362.  
  363. /* Clear out all variables saying what to do when inferior is continued.
  364.    First do this, then set the ones you want, then call `proceed'.  */
  365.  
  366. void
  367. clear_proceed_status ()
  368. {
  369.   trap_expected = 0;
  370.   step_range_start = 0;
  371.   step_range_end = 0;
  372.   step_frame_address = 0;
  373.   step_over_calls = -1;
  374.   step_resume_break_address = 0;
  375.   stop_after_trap = 0;
  376.   stop_soon_quietly = 0;
  377.   proceed_to_finish = 0;
  378.   breakpoint_proceeded = 1;    /* We're about to proceed... */
  379.  
  380.   /* Discard any remaining commands or status from previous stop.  */
  381.   bpstat_clear (&stop_bpstat);
  382. }
  383.  
  384. /* Basic routine for continuing the program in various fashions.
  385.  
  386.    ADDR is the address to resume at, or -1 for resume where stopped.
  387.    SIGGNAL is the signal to give it, or 0 for none,
  388.      or -1 for act according to how it stopped.
  389.    STEP is nonzero if should trap after one instruction.
  390.      -1 means return after that and print nothing.
  391.      You should probably set various step_... variables
  392.      before calling here, if you are stepping.
  393.  
  394.    You should call clear_proceed_status before calling proceed.  */
  395.  
  396. void
  397. proceed (addr, siggnal, step)
  398.      CORE_ADDR addr;
  399.      int siggnal;
  400.      int step;
  401. {
  402.   int oneproc = 0;
  403.  
  404.   if (step > 0)
  405.     step_start_function = find_pc_function (read_pc ());
  406.   if (step < 0)
  407.     stop_after_trap = 1;
  408.  
  409.   if (addr == (CORE_ADDR)-1)
  410.     {
  411.       /* If there is a breakpoint at the address we will resume at,
  412.      step one instruction before inserting breakpoints
  413.      so that we do not stop right away.  */
  414.  
  415.       if (!pc_changed && breakpoint_here_p (read_pc ()))
  416.     oneproc = 1;
  417.     }
  418.   else
  419.     {
  420.       write_register (PC_REGNUM, addr);
  421. #ifdef NPC_REGNUM
  422.       write_register (NPC_REGNUM, addr + 4);
  423. #ifdef NNPC_REGNUM
  424.       write_register (NNPC_REGNUM, addr + 8);
  425. #endif
  426. #endif
  427.     }
  428.  
  429.   if (trap_expected_after_continue)
  430.     {
  431.       /* If (step == 0), a trap will be automatically generated after
  432.      the first instruction is executed.  Force step one
  433.      instruction to clear this condition.  This should not occur
  434.      if step is nonzero, but it is harmless in that case.  */
  435.       oneproc = 1;
  436.       trap_expected_after_continue = 0;
  437.     }
  438.  
  439.   if (oneproc)
  440.     /* We will get a trace trap after one instruction.
  441.        Continue it automatically and insert breakpoints then.  */
  442.     trap_expected = 1;
  443.   else
  444.     {
  445.       int temp = insert_breakpoints ();
  446.       if (temp)
  447.     {
  448.       print_sys_errmsg ("ptrace", temp);
  449.       error ("Cannot insert breakpoints.\n\
  450. The same program may be running in another process.");
  451.     }
  452.       breakpoints_inserted = 1;
  453.     }
  454.  
  455.   /* Install inferior's terminal modes.  */
  456.   target_terminal_inferior ();
  457.  
  458.   if (siggnal >= 0)
  459.     stop_signal = siggnal;
  460.   /* If this signal should not be seen by program,
  461.      give it zero.  Used for debugging signals.  */
  462.   else if (stop_signal < NSIG && !signal_program[stop_signal])
  463.     stop_signal= 0;
  464.  
  465.   /* Resume inferior.  */
  466.   resume (oneproc || step || bpstat_should_step (), stop_signal);
  467.  
  468.   /* Wait for it to stop (if not standalone)
  469.      and in any case decode why it stopped, and act accordingly.  */
  470.  
  471.   wait_for_inferior ();
  472.   normal_stop ();
  473. }
  474.  
  475. /* Record the pc and sp of the program the last time it stopped.
  476.    These are just used internally by wait_for_inferior, but need
  477.    to be preserved over calls to it and cleared when the inferior
  478.    is started.  */
  479. static CORE_ADDR prev_pc;
  480. static CORE_ADDR prev_sp;
  481. static CORE_ADDR prev_func_start;
  482. static char *prev_func_name;
  483.  
  484.  
  485. /* Start an inferior Unix child process and sets inferior_pid to its pid.
  486.    EXEC_FILE is the file to run.
  487.    ALLARGS is a string containing the arguments to the program.
  488.    ENV is the environment vector to pass.  Errors reported with error().  */
  489.  
  490. #ifndef SHELL_FILE
  491. #define SHELL_FILE "/bin/sh"
  492. #endif
  493.  
  494. void
  495. child_create_inferior (exec_file, allargs, env)
  496.      char *exec_file;
  497.      char *allargs;
  498.      char **env;
  499. {
  500.   int pid;
  501.   char *shell_command;
  502.   char *shell_file;
  503.   static char default_shell_file[] = SHELL_FILE;
  504.   int len;
  505.   int pending_execs;
  506.   /* Set debug_fork then attach to the child while it sleeps, to debug. */
  507.   static int debug_fork = 0;
  508.   /* This is set to the result of setpgrp, which if vforked, will be visible
  509.      to you in the parent process.  It's only used by humans for debugging.  */
  510.   static int debug_setpgrp = 657473;
  511.   char **save_our_env;
  512.  
  513.   /* The user might want tilde-expansion, and in general probably wants
  514.      the program to behave the same way as if run from
  515.      his/her favorite shell.  So we let the shell run it for us.
  516.      FIXME, this should probably search the local environment (as
  517.      modified by the setenv command), not the env gdb inherited.  */
  518.   shell_file = getenv ("SHELL");
  519.   if (shell_file == NULL)
  520.     shell_file = default_shell_file;
  521.   
  522.   len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
  523.   /* If desired, concat something onto the front of ALLARGS.
  524.      SHELL_COMMAND is the result.  */
  525. #ifdef SHELL_COMMAND_CONCAT
  526.   shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len);
  527.   strcpy (shell_command, SHELL_COMMAND_CONCAT);
  528. #else
  529.   shell_command = (char *) alloca (len);
  530.   shell_command[0] = '\0';
  531. #endif
  532.   strcat (shell_command, "exec ");
  533. #ifdef sprite
  534.   strcat (shell_command, "debug ");
  535. #endif
  536.   strcat (shell_command, exec_file);
  537.   strcat (shell_command, " ");
  538.   strcat (shell_command, allargs);
  539.  
  540.   /* exec is said to fail if the executable is open.  */
  541.   close_exec_file ();
  542.  
  543.   /* Retain a copy of our environment variables, since the child will
  544.      replace the value of  environ  and if we're vforked, we have to 
  545.      restore it.  */
  546.   save_our_env = environ;
  547.  
  548.   /* Tell the terminal handling subsystem what tty we plan to run on;
  549.      it will just record the information for later.  */
  550.  
  551.   new_tty_prefork (inferior_io_terminal);
  552.  
  553.   /* It is generally good practice to flush any possible pending stdio
  554.      output prior to doing a fork, to avoid the possibility of both the
  555.      parent and child flushing the same data after the fork. */
  556.  
  557.   fflush (stdout);
  558.   fflush (stderr);
  559.  
  560. #ifdef sprite
  561.   pid = fork();
  562. #else
  563. #if defined(USG) && !defined(HAVE_VFORK)
  564.   pid = fork ();
  565. #else
  566.   if (debug_fork)
  567.     pid = fork ();
  568.   else
  569.     pid = vfork ();
  570. #endif
  571. #endif
  572.  
  573.   if (pid < 0)
  574.     perror_with_name ("vfork");
  575.  
  576.   if (pid == 0)
  577.     {
  578.       if (debug_fork) 
  579.     sleep (debug_fork);
  580.  
  581. #ifdef TIOCGPGRP
  582.       /* Run inferior in a separate process group.  */
  583. #ifdef NEED_POSIX_SETPGID
  584.       debug_setpgrp = setpgid (0, 0);
  585. #else
  586. #if defined(USG) && !defined(SETPGRP_ARGS)
  587.       debug_setpgrp = setpgrp ();
  588. #else
  589.       debug_setpgrp = setpgrp (getpid (), getpid ());
  590. #endif /* USG */
  591. #endif /* NEED_POSIX_SETPGID */
  592.       if (debug_setpgrp == -1)
  593.      perror("setpgrp failed in child");
  594. #endif /* TIOCGPGRP */
  595.  
  596. #ifdef SET_STACK_LIMIT_HUGE
  597.       /* Reset the stack limit back to what it was.  */
  598.       {
  599.     struct rlimit rlim;
  600.  
  601.     getrlimit (RLIMIT_STACK, &rlim);
  602.     rlim.rlim_cur = original_stack_limit;
  603.     setrlimit (RLIMIT_STACK, &rlim);
  604.       }
  605. #endif /* SET_STACK_LIMIT_HUGE */
  606.  
  607.       /* Ask the tty subsystem to switch to the one we specified earlier
  608.      (or to share the current terminal, if none was specified).  */
  609.  
  610.       new_tty ();
  611.  
  612.       /* Changing the signal handlers for the inferior after
  613.      a vfork can also change them for the superior, so we don't mess
  614.      with signals here.  See comments in
  615.      initialize_signals for how we get the right signal handlers
  616.      for the inferior.  */
  617.  
  618. #ifdef sprite
  619.       /*
  620.        * This appears to be needed on Sprite.
  621.        */
  622.       signal (SIGQUIT, SIG_DFL);
  623.       signal (SIGINT, SIG_DFL);
  624. #endif
  625.  
  626. #ifdef USE_PROC_FS
  627.       proc_set_exec_trap ();        /* Use SVR4 /proc interface */
  628. #else
  629.       call_ptrace (0, 0, 0, 0);        /* "Trace me, Dr. Memory!" */
  630. #endif
  631.  
  632.       /* There is no execlpe call, so we have to set the environment
  633.      for our child in the global variable.  If we've vforked, this
  634.      clobbers the parent, but environ is restored a few lines down
  635.      in the parent.  By the way, yes we do need to look down the
  636.      path to find $SHELL.  Rich Pixley says so, and I agree.  */
  637.       environ = env;
  638.       execlp (shell_file, shell_file, "-c", shell_command, (char *)0);
  639.       fprintf (stderr, "Cannot exec %s: %s.\n", shell_file,
  640.            errno < sys_nerr ? sys_errlist[errno] : "unknown error");
  641.       fflush (stderr);
  642.       _exit (0177);
  643.     }
  644.  
  645.   /* Restore our environment in case a vforked child clob'd it.  */
  646.   environ = save_our_env;
  647.  
  648.   /* Now that we have a child process, make it our target.  */
  649.   push_target (&child_ops);
  650.  
  651. #ifdef CREATE_INFERIOR_HOOK
  652.   CREATE_INFERIOR_HOOK (pid);
  653. #endif  
  654.  
  655. /* The process was started by the fork that created it,
  656.    but it will have stopped one instruction after execing the shell.
  657.    Here we must get it up to actual execution of the real program.  */
  658.  
  659.   inferior_pid = pid;        /* Needed for wait_for_inferior stuff below */
  660.  
  661.   clear_proceed_status ();
  662.  
  663.   /* We will get a trace trap after one instruction.
  664.      Continue it automatically.  Eventually (after shell does an exec)
  665.      it will get another trace trap.  Then insert breakpoints and continue.  */
  666.  
  667. #ifdef START_INFERIOR_TRAPS_EXPECTED
  668.   pending_execs = START_INFERIOR_TRAPS_EXPECTED;
  669. #else
  670.   pending_execs = 2;
  671. #endif
  672.  
  673.   init_wait_for_inferior ();
  674.  
  675.   /* Set up the "saved terminal modes" of the inferior
  676.      based on what modes we are starting it with.  */
  677.   target_terminal_init ();
  678.  
  679.   /* Install inferior's terminal modes.  */
  680.   target_terminal_inferior ();
  681.  
  682.   while (1)
  683.     {
  684.       stop_soon_quietly = 1;    /* Make wait_for_inferior be quiet */
  685.       wait_for_inferior ();
  686.       if (stop_signal != SIGTRAP)
  687.     {
  688.       /* Let shell child handle its own signals in its own way */
  689.       /* FIXME, what if child has exit()ed?  Must exit loop somehow */
  690.       resume (0, stop_signal);
  691.     }
  692.       else
  693.     {
  694.       /* We handle SIGTRAP, however; it means child did an exec.  */
  695.       if (0 == --pending_execs)
  696.         break;
  697.       resume (0, 0);        /* Just make it go on */
  698.     }
  699.     }
  700.   stop_soon_quietly = 0;
  701.  
  702.   /* We are now in the child process of interest, having exec'd the
  703.      correct program, and are poised at the first instruction of the
  704.      new program.  */
  705. #ifdef SOLIB_CREATE_INFERIOR_HOOK
  706.   SOLIB_CREATE_INFERIOR_HOOK (pid);
  707. #endif
  708.  
  709.   /* Should this perhaps just be a "proceed" call?  FIXME */
  710.   insert_step_breakpoint ();
  711.   breakpoints_failed = insert_breakpoints ();
  712.   if (!breakpoints_failed)
  713.     {
  714.       breakpoints_inserted = 1;
  715.       target_terminal_inferior();
  716.       /* Start the child program going on its first instruction, single-
  717.      stepping if we need to.  */
  718.       resume (bpstat_should_step (), 0);
  719.       wait_for_inferior ();
  720.       normal_stop ();
  721.     }
  722. }
  723.  
  724. /* Start remote-debugging of a machine over a serial link.  */
  725.  
  726. void
  727. start_remote ()
  728. {
  729.   init_wait_for_inferior ();
  730.   clear_proceed_status ();
  731.   stop_soon_quietly = 1;
  732.   trap_expected = 0;
  733.   wait_for_inferior ();
  734.   normal_stop ();
  735. }
  736.  
  737. /* Initialize static vars when a new inferior begins.  */
  738.  
  739. void
  740. init_wait_for_inferior ()
  741. {
  742.   /* These are meaningless until the first time through wait_for_inferior.  */
  743.   prev_pc = 0;
  744.   prev_sp = 0;
  745.   prev_func_start = 0;
  746.   prev_func_name = NULL;
  747.  
  748.   trap_expected_after_continue = 0;
  749.   breakpoints_inserted = 0;
  750.   mark_breakpoints_out ();
  751.   stop_signal = 0;        /* Don't confuse first call to proceed(). */
  752. }
  753.  
  754.  
  755. /* Attach to process PID, then initialize for debugging it
  756.    and wait for the trace-trap that results from attaching.  */
  757.  
  758. void
  759. child_attach (args, from_tty)
  760.      char *args;
  761.      int from_tty;
  762. {
  763.   char *exec_file;
  764.   int pid;
  765.  
  766.   dont_repeat();
  767.  
  768.   if (!args)
  769.     error_no_arg ("process-id to attach");
  770.  
  771. #ifndef ATTACH_DETACH
  772.   error ("Can't attach to a process on this machine.");
  773. #else
  774. #ifdef sprite
  775.   /*
  776.    * Since Sprite pids are displayed in hex the atoi doesn't work. We
  777.    * allow the attach command to use any C expression.
  778.    */
  779.   pid = value_as_long (evaluate_expression (parse_expression (args)));
  780. #else
  781.   pid = atoi (args);
  782. #endif /* Sprite */
  783.   if (target_has_execution)
  784.     {
  785.       if (query ("A program is being debugged already.  Kill it? "))
  786.     target_kill ();
  787.       else
  788.     error ("Inferior not killed.");
  789.     }
  790.  
  791.   exec_file = (char *) get_exec_file (1);
  792.  
  793.   if (from_tty)
  794.     {
  795.       printf ("Attaching program: %s pid %d\n",
  796.           exec_file, pid);
  797.       fflush (stdout);
  798.     }
  799.  
  800.   attach (pid);
  801.   inferior_pid = pid;
  802.   push_target (&child_ops);
  803.  
  804.   mark_breakpoints_out ();
  805.   target_terminal_init ();
  806.   clear_proceed_status ();
  807.   stop_soon_quietly = 1;
  808.   /*proceed (-1, 0, -2);*/
  809.   target_terminal_inferior ();
  810.   wait_for_inferior ();
  811. #ifdef SOLIB_ADD
  812.   SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
  813. #endif
  814.   normal_stop ();
  815. #endif  /* ATTACH_DETACH */
  816. }
  817.  
  818. /* Wait for control to return from inferior to debugger.
  819.    If inferior gets a signal, we may decide to start it up again
  820.    instead of returning.  That is why there is a loop in this function.
  821.    When this function actually returns it means the inferior
  822.    should be left stopped and GDB should read more commands.  */
  823.  
  824. void
  825. wait_for_inferior ()
  826. {
  827.   WAITTYPE w;
  828.   int another_trap;
  829.   int random_signal;
  830.   CORE_ADDR stop_sp;
  831.   CORE_ADDR stop_func_start;
  832.   char *stop_func_name;
  833.   CORE_ADDR prologue_pc, tmp;
  834.   int stop_step_resume_break;
  835.   struct symtab_and_line sal;
  836.   int remove_breakpoints_on_following_step = 0;
  837.   int current_line;
  838.   int handling_longjmp = 0;    /* FIXME */
  839.  
  840.   sal = find_pc_line(prev_pc, 0);
  841.   current_line = sal.line;
  842.  
  843.   while (1)
  844.     {
  845.       /* Clean up saved state that will become invalid.  */
  846.       pc_changed = 0;
  847.       flush_cached_frames ();
  848.       registers_changed ();
  849.  
  850.       target_wait (&w);
  851.  
  852. #ifdef SIGTRAP_STOP_AFTER_LOAD
  853.  
  854.       /* Somebody called load(2), and it gave us a "trap signal after load".
  855.          Ignore it gracefully. */
  856.  
  857.       SIGTRAP_STOP_AFTER_LOAD (w);
  858. #endif
  859.  
  860.       /* See if the process still exists; clean up if it doesn't.  */
  861.       if (WIFEXITED (w))
  862.     {
  863.       target_terminal_ours ();    /* Must do this before mourn anyway */
  864.       if (WEXITSTATUS (w))
  865.         printf ("\nProgram exited with code 0%o.\n", 
  866.              (unsigned int)WEXITSTATUS (w));
  867.       else
  868.         if (!batch_mode())
  869.           printf ("\nProgram exited normally.\n");
  870.       fflush (stdout);
  871.       target_mourn_inferior ();
  872. #ifdef NO_SINGLE_STEP
  873.       one_stepped = 0;
  874. #endif
  875.       stop_print_frame = 0;
  876.       break;
  877.     }
  878.       else if (!WIFSTOPPED (w))
  879.     {
  880.       stop_print_frame = 0;
  881.       stop_signal = WTERMSIG (w);
  882.       target_terminal_ours ();    /* Must do this before mourn anyway */
  883.       target_kill ();        /* kill mourns as well */
  884. #ifdef PRINT_RANDOM_SIGNAL
  885.       printf ("\nProgram terminated: ");
  886.       PRINT_RANDOM_SIGNAL (stop_signal);
  887. #else
  888.       printf ("\nProgram terminated with signal %d, %s\n",
  889.           stop_signal,
  890.           stop_signal < NSIG
  891.           ? sys_siglist[stop_signal]
  892.           : "(undocumented)");
  893. #endif
  894.       printf ("The inferior process no longer exists.\n");
  895.       fflush (stdout);
  896. #ifdef NO_SINGLE_STEP
  897.       one_stepped = 0;
  898. #endif
  899.       break;
  900.     }
  901.       
  902. #ifdef NO_SINGLE_STEP
  903.       if (one_stepped)
  904.     single_step (0);    /* This actually cleans up the ss */
  905. #endif /* NO_SINGLE_STEP */
  906.       
  907.       stop_pc = read_pc ();
  908.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  909.                         read_pc ()));
  910.       
  911.       stop_frame_address = FRAME_FP (get_current_frame ());
  912.       stop_sp = read_register (SP_REGNUM);
  913.       stop_func_start = 0;
  914.       stop_func_name = 0;
  915.       /* Don't care about return value; stop_func_start and stop_func_name
  916.      will both be 0 if it doesn't work.  */
  917.       (void) find_pc_partial_function (stop_pc, &stop_func_name,
  918.                        &stop_func_start);
  919.       stop_func_start += FUNCTION_START_OFFSET;
  920.       another_trap = 0;
  921.       bpstat_clear (&stop_bpstat);
  922.       stop_step = 0;
  923.       stop_stack_dummy = 0;
  924.       stop_print_frame = 1;
  925.       stop_step_resume_break = 0;
  926.       random_signal = 0;
  927.       stopped_by_random_signal = 0;
  928.       breakpoints_failed = 0;
  929.       
  930.       /* Look at the cause of the stop, and decide what to do.
  931.      The alternatives are:
  932.      1) break; to really stop and return to the debugger,
  933.      2) drop through to start up again
  934.      (set another_trap to 1 to single step once)
  935.      3) set random_signal to 1, and the decision between 1 and 2
  936.      will be made according to the signal handling tables.  */
  937.       
  938.       stop_signal = WSTOPSIG (w);
  939.       
  940.       /* First, distinguish signals caused by the debugger from signals
  941.      that have to do with the program's own actions.
  942.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  943.      or SIGEMT, depending on the operating system version.
  944.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  945.      and change it to SIGTRAP.  */
  946.       
  947.       if (stop_signal == SIGTRAP
  948.       || (breakpoints_inserted &&
  949.           (stop_signal == SIGILL
  950.            || stop_signal == SIGEMT))
  951.       || stop_soon_quietly)
  952.     {
  953.       if (stop_signal == SIGTRAP && stop_after_trap)
  954.         {
  955.           stop_print_frame = 0;
  956.           break;
  957.         }
  958.       if (stop_soon_quietly)
  959.         break;
  960.  
  961.       /* Don't even think about breakpoints
  962.          if just proceeded over a breakpoint.
  963.  
  964.          However, if we are trying to proceed over a breakpoint
  965.          and end up in sigtramp, then step_resume_break_address
  966.          will be set and we should check whether we've hit the
  967.          step breakpoint.  */
  968.       if (stop_signal == SIGTRAP && trap_expected
  969.           && step_resume_break_address == 0)
  970.         bpstat_clear (&stop_bpstat);
  971.       else
  972.         {
  973.           /* See if there is a breakpoint at the current PC.  */
  974. #if DECR_PC_AFTER_BREAK
  975.           /* Notice the case of stepping through a jump
  976.          that lands just after a breakpoint.
  977.          Don't confuse that with hitting the breakpoint.
  978.          What we check for is that 1) stepping is going on
  979.          and 2) the pc before the last insn does not match
  980.          the address of the breakpoint before the current pc.  */
  981.           if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK
  982.           || !step_range_end
  983.           || step_resume_break_address
  984.           || handling_longjmp /* FIXME */)
  985. #endif /* DECR_PC_AFTER_BREAK not zero */
  986.         {
  987.           /* See if we stopped at the special breakpoint for
  988.              stepping over a subroutine call.  If both are zero,
  989.              this wasn't the reason for the stop.  */
  990.           if (step_resume_break_address
  991.               && stop_pc - DECR_PC_AFTER_BREAK
  992.                  == step_resume_break_address)
  993.             {
  994.               stop_step_resume_break = 1;
  995.               if (DECR_PC_AFTER_BREAK)
  996.             {
  997.               stop_pc -= DECR_PC_AFTER_BREAK;
  998.               write_register (PC_REGNUM, stop_pc);
  999.               pc_changed = 0;
  1000.             }
  1001.             }
  1002.           else
  1003.             {
  1004.               stop_bpstat =
  1005.             bpstat_stop_status (&stop_pc, stop_frame_address);
  1006.               /* Following in case break condition called a
  1007.              function.  */
  1008.               stop_print_frame = 1;
  1009.             }
  1010.         }
  1011.         }
  1012.       
  1013.       if (stop_signal == SIGTRAP)
  1014.         random_signal
  1015.           = !(bpstat_explains_signal (stop_bpstat)
  1016.           || trap_expected
  1017.           || stop_step_resume_break
  1018.           || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  1019.           || (step_range_end && !step_resume_break_address));
  1020.       else
  1021.         {
  1022.           random_signal
  1023.         = !(bpstat_explains_signal (stop_bpstat)
  1024.             || stop_step_resume_break
  1025.             /* End of a stack dummy.  Some systems (e.g. Sony
  1026.                news) give another signal besides SIGTRAP,
  1027.                so check here as well as above.  */
  1028.             || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  1029.             );
  1030.           if (!random_signal)
  1031.         stop_signal = SIGTRAP;
  1032.         }
  1033.     }
  1034.       else
  1035.     random_signal = 1;
  1036.       
  1037.       /* For the program's own signals, act according to
  1038.      the signal handling tables.  */
  1039.  
  1040.       if (random_signal)
  1041.     {
  1042.       /* Signal not for debugging purposes.  */
  1043.       int printed = 0;
  1044.       
  1045.       stopped_by_random_signal = 1;
  1046.       
  1047.       if (stop_signal >= NSIG
  1048.           || signal_print[stop_signal])
  1049.         {
  1050.           printed = 1;
  1051.           target_terminal_ours_for_output ();
  1052. #ifdef PRINT_RANDOM_SIGNAL
  1053.           PRINT_RANDOM_SIGNAL (stop_signal);
  1054. #else
  1055.           printf ("\nProgram received signal %d, %s\n",
  1056.               stop_signal,
  1057.               stop_signal < NSIG
  1058.               ? sys_siglist[stop_signal]
  1059.               : "(undocumented)");
  1060. #endif /* PRINT_RANDOM_SIGNAL */
  1061.           fflush (stdout);
  1062.         }
  1063.       if (stop_signal >= NSIG
  1064.           || signal_stop[stop_signal])
  1065.         break;
  1066.       /* If not going to stop, give terminal back
  1067.          if we took it away.  */
  1068.       else if (printed)
  1069.         target_terminal_inferior ();
  1070.  
  1071.       /* Note that virtually all the code below does `if !random_signal'.
  1072.          Perhaps this code should end with a goto or continue.  At least
  1073.          one (now fixed) bug was caused by this -- a !random_signal was
  1074.          missing in one of the tests below.  */
  1075.     }
  1076.  
  1077.       /* Handle cases caused by hitting a breakpoint.  */
  1078.  
  1079.       if (!random_signal)
  1080.     if (bpstat_explains_signal (stop_bpstat))
  1081.       {
  1082.         CORE_ADDR jmp_buf_pc;
  1083.  
  1084.         switch (stop_bpstat->breakpoint_at->type) /* FIXME */
  1085.           {
  1086.         /* If we hit the breakpoint at longjmp, disable it for the
  1087.            duration of this command.  Then, install a temporary
  1088.            breakpoint at the target of the jmp_buf. */
  1089.           case bp_longjmp:
  1090.         disable_longjmp_breakpoint();
  1091.         remove_breakpoints ();
  1092.         breakpoints_inserted = 0;
  1093.         if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
  1094.  
  1095.         /* Need to blow away step-resume breakpoint, as it
  1096.            interferes with us */
  1097.         remove_step_breakpoint ();
  1098.         step_resume_break_address = 0;
  1099.         stop_step_resume_break = 0;
  1100.  
  1101. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1102.         if (step_over_calls > 0)
  1103.           set_longjmp_resume_breakpoint(jmp_buf_pc,
  1104.                         get_current_frame());
  1105.         else
  1106. #endif                /* 0 */
  1107.           set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
  1108.         handling_longjmp = 1; /* FIXME */
  1109.         goto keep_going;
  1110.  
  1111.           case bp_longjmp_resume:
  1112.         remove_breakpoints ();
  1113.         breakpoints_inserted = 0;
  1114. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1115.         if (step_over_calls
  1116.             && (stop_frame_address
  1117.             INNER_THAN step_frame_address))
  1118.           {
  1119.             another_trap = 1;
  1120.             goto keep_going;
  1121.           }
  1122. #endif                /* 0 */
  1123.         disable_longjmp_breakpoint();
  1124.         handling_longjmp = 0; /* FIXME */
  1125.         break;
  1126.  
  1127.           default:
  1128.         fprintf(stderr, "Unknown breakpoint type %d\n",
  1129.             stop_bpstat->breakpoint_at->type);
  1130.           case bp_watchpoint:
  1131.           case bp_breakpoint:
  1132.           case bp_until:
  1133.           case bp_finish:
  1134.         /* Does a breakpoint want us to stop?  */
  1135.         if (bpstat_stop (stop_bpstat))
  1136.           {
  1137.             stop_print_frame = bpstat_should_print (stop_bpstat);
  1138.             goto stop_stepping;
  1139.           }
  1140.         /* Otherwise, must remove breakpoints and single-step
  1141.            to get us past the one we hit.  */
  1142.         else
  1143.           {
  1144.             remove_breakpoints ();
  1145.             remove_step_breakpoint ();
  1146.             breakpoints_inserted = 0;
  1147.             another_trap = 1;
  1148.           }
  1149.         break;
  1150.           }
  1151.       }
  1152.     else if (stop_step_resume_break)
  1153.       {
  1154.         /* But if we have hit the step-resumption breakpoint,
  1155.            remove it.  It has done its job getting us here.
  1156.            The sp test is to make sure that we don't get hung
  1157.            up in recursive calls in functions without frame
  1158.            pointers.  If the stack pointer isn't outside of
  1159.            where the breakpoint was set (within a routine to be
  1160.            stepped over), we're in the middle of a recursive
  1161.            call. Not true for reg window machines (sparc)
  1162.            because the must change frames to call things and
  1163.            the stack pointer doesn't have to change if it
  1164.            the bp was set in a routine without a frame (pc can
  1165.            be stored in some other window).
  1166.            
  1167.            The removal of the sp test is to allow calls to
  1168.            alloca.  Nasty things were happening.  Oh, well,
  1169.            gdb can only handle one level deep of lack of
  1170.            frame pointer. */
  1171.  
  1172.         /*
  1173.           Disable test for step_frame_address match so that we always stop even if the
  1174.           frames don't match.  Reason: if we hit the step_resume_breakpoint, there is
  1175.           no way to temporarily disable it so that we can step past it.  If we leave
  1176.           the breakpoint in, then we loop forever repeatedly hitting, but never
  1177.           getting past the breakpoint.  This change keeps nexting over recursive
  1178.           function calls from hanging gdb.
  1179.           */
  1180. #if 0
  1181.         if (* step_frame_address == 0
  1182.         || (step_frame_address == stop_frame_address))
  1183. #endif
  1184.           {
  1185.         remove_step_breakpoint ();
  1186.         step_resume_break_address = 0;
  1187.  
  1188.         /* If were waiting for a trap, hitting the step_resume_break
  1189.            doesn't count as getting it.  */
  1190.         if (trap_expected)
  1191.           another_trap = 1;
  1192.           }
  1193.       }
  1194.  
  1195.       /* We come here if we hit a breakpoint but should not
  1196.      stop for it.  Possibly we also were stepping
  1197.      and should stop for that.  So fall through and
  1198.      test for stepping.  But, if not stepping,
  1199.      do not stop.  */
  1200.  
  1201.       /* If this is the breakpoint at the end of a stack dummy,
  1202.      just stop silently.  */
  1203.       if (!random_signal 
  1204.      && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
  1205.       {
  1206.         stop_print_frame = 0;
  1207.         stop_stack_dummy = 1;
  1208. #ifdef HP_OS_BUG
  1209.         trap_expected_after_continue = 1;
  1210. #endif
  1211.         break;
  1212.       }
  1213.       
  1214.       if (step_resume_break_address)
  1215.     /* Having a step-resume breakpoint overrides anything
  1216.        else having to do with stepping commands until
  1217.        that breakpoint is reached.  */
  1218.     ;
  1219.       /* If stepping through a line, keep going if still within it.  */
  1220.       else if (!random_signal
  1221.            && step_range_end
  1222.            && stop_pc >= step_range_start
  1223.            && stop_pc < step_range_end
  1224.            /* The step range might include the start of the
  1225.           function, so if we are at the start of the
  1226.           step range and either the stack or frame pointers
  1227.           just changed, we've stepped outside */
  1228.            && !(stop_pc == step_range_start
  1229.             && stop_frame_address
  1230.             && (stop_sp INNER_THAN prev_sp
  1231.             || stop_frame_address != step_frame_address)))
  1232.     {
  1233.       ;
  1234.     }
  1235.       
  1236.       /* We stepped out of the stepping range.  See if that was due
  1237.      to a subroutine call that we should proceed to the end of.  */
  1238.       else if (!random_signal && step_range_end)
  1239.     {
  1240.       if (stop_func_start)
  1241.         {
  1242.           prologue_pc = stop_func_start;
  1243.           SKIP_PROLOGUE (prologue_pc);
  1244.         }
  1245.  
  1246.       /* Did we just take a signal?  */
  1247.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  1248.           && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1249.         {
  1250.           /* This code is needed at least in the following case:
  1251.          The user types "next" and then a signal arrives (before
  1252.          the "next" is done).  */
  1253.           /* We've just taken a signal; go until we are back to
  1254.          the point where we took it and one more.  */
  1255.           step_resume_break_address = prev_pc;
  1256.           step_resume_break_duplicate =
  1257.         breakpoint_here_p (step_resume_break_address);
  1258.           if (breakpoints_inserted)
  1259.         insert_step_breakpoint ();
  1260.           /* Make sure that the stepping range gets us past
  1261.          that instruction.  */
  1262.           if (step_range_end == 1)
  1263.         step_range_end = (step_range_start = prev_pc) + 1;
  1264.           remove_breakpoints_on_following_step = 1;
  1265.           goto save_pc;
  1266.         }
  1267.  
  1268.       /* ==> See comments at top of file on this algorithm.  <==*/
  1269.       
  1270.       if ((stop_pc == stop_func_start
  1271.            || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name))
  1272.           && (stop_func_start != prev_func_start
  1273.           || prologue_pc != stop_func_start
  1274.           || stop_sp != prev_sp))
  1275.         {
  1276.           /* It's a subroutine call.
  1277.          (0)  If we are not stepping over any calls ("stepi"), we
  1278.               just stop.
  1279.          (1)  If we're doing a "next", we want to continue through
  1280.               the call ("step over the call").
  1281.          (2)  If we are in a function-call trampoline (a stub between
  1282.               the calling routine and the real function), locate
  1283.               the real function and change stop_func_start.
  1284.          (3)  If we're doing a "step", and there are no debug symbols
  1285.               at the target of the call, we want to continue through
  1286.               it ("step over the call").
  1287.          (4)  Otherwise, we want to stop soon, after the function
  1288.               prologue ("step into the call"). */
  1289.  
  1290.           if (step_over_calls == 0)
  1291.         {
  1292.           /* I presume that step_over_calls is only 0 when we're
  1293.              supposed to be stepping at the assembly language level. */
  1294.           stop_step = 1;
  1295.           break;
  1296.         }
  1297.  
  1298.           if (step_over_calls > 0)
  1299.         goto step_over_function;
  1300.  
  1301.           tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
  1302.           if (tmp != 0)
  1303.         stop_func_start = tmp;
  1304.  
  1305.           if (find_pc_function (stop_func_start) != 0)
  1306.             goto step_into_function;
  1307.  
  1308. step_over_function:
  1309.           /* A subroutine call has happened.  */
  1310.           /* Set a special breakpoint after the return */
  1311.           step_resume_break_address =
  1312.         ADDR_BITS_REMOVE
  1313.           (SAVED_PC_AFTER_CALL (get_current_frame ()));
  1314.           step_resume_break_duplicate
  1315.         = breakpoint_here_p (step_resume_break_address);
  1316.           if (breakpoints_inserted)
  1317.         insert_step_breakpoint ();
  1318.           goto save_pc;
  1319.  
  1320. step_into_function:
  1321.           /* Subroutine call with source code we should not step over.
  1322.          Do step to the first line of code in it.  */
  1323.           SKIP_PROLOGUE (stop_func_start);
  1324.           sal = find_pc_line (stop_func_start, 0);
  1325.           /* Use the step_resume_break to step until
  1326.          the end of the prologue, even if that involves jumps
  1327.          (as it seems to on the vax under 4.2).  */
  1328.           /* If the prologue ends in the middle of a source line,
  1329.          continue to the end of that source line.
  1330.          Otherwise, just go to end of prologue.  */
  1331. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  1332.           /* no, don't either.  It skips any code that's
  1333.          legitimately on the first line.  */
  1334. #else
  1335.           if (sal.end && sal.pc != stop_func_start)
  1336.         stop_func_start = sal.end;
  1337. #endif
  1338.  
  1339.           if (stop_func_start == stop_pc)
  1340.         {
  1341.           /* We are already there: stop now.  */
  1342.           stop_step = 1;
  1343.           break;
  1344.         }    
  1345.           else
  1346.         /* Put the step-breakpoint there and go until there. */
  1347.         {
  1348.           step_resume_break_address = stop_func_start;
  1349.           
  1350.           step_resume_break_duplicate
  1351.             = breakpoint_here_p (step_resume_break_address);
  1352.           if (breakpoints_inserted)
  1353.             insert_step_breakpoint ();
  1354.           /* Do not specify what the fp should be when we stop
  1355.              since on some machines the prologue
  1356.              is where the new fp value is established.  */
  1357.           step_frame_address = 0;
  1358.           /* And make sure stepping stops right away then.  */
  1359.           step_range_end = step_range_start;
  1360.         }
  1361.           goto save_pc;
  1362.         }
  1363.  
  1364.       /* We've wandered out of the step range (but haven't done a
  1365.          subroutine call or return).  */
  1366.  
  1367.       sal = find_pc_line(stop_pc, 0);
  1368.       
  1369.       if (step_range_end == 1 ||    /* stepi or nexti */
  1370.           sal.line == 0 ||        /* ...or no line # info */
  1371.           (stop_pc == sal.pc    /* ...or we're at the start */
  1372.            && current_line != sal.line)) {    /* of a different line */
  1373.         /* Stop because we're done stepping.  */
  1374.         stop_step = 1;
  1375.         break;
  1376.       } else {
  1377.         /* We aren't done stepping, and we have line number info for $pc.
  1378.            Optimize by setting the step_range for the line.  
  1379.            (We might not be in the original line, but if we entered a
  1380.            new line in mid-statement, we continue stepping.  This makes 
  1381.            things like for(;;) statements work better.)  */
  1382.         step_range_start = sal.pc;
  1383.         step_range_end = sal.end;
  1384.         goto save_pc;
  1385.       }
  1386.       /* We never fall through here */
  1387.     }
  1388.  
  1389.       if (trap_expected
  1390.       && IN_SIGTRAMP (stop_pc, stop_func_name)
  1391.       && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1392.     {
  1393.       /* What has happened here is that we have just stepped the inferior
  1394.          with a signal (because it is a signal which shouldn't make
  1395.          us stop), thus stepping into sigtramp.
  1396.  
  1397.          So we need to set a step_resume_break_address breakpoint
  1398.          and continue until we hit it, and then step.  */
  1399.       step_resume_break_address = prev_pc;
  1400.       /* Always 1, I think, but it's probably easier to have
  1401.          the step_resume_break as usual rather than trying to
  1402.          re-use the breakpoint which is already there.  */
  1403.       step_resume_break_duplicate =
  1404.         breakpoint_here_p (step_resume_break_address);
  1405.       if (breakpoints_inserted)
  1406.         insert_step_breakpoint ();
  1407.       remove_breakpoints_on_following_step = 1;
  1408.       another_trap = 1;
  1409.     }
  1410.  
  1411. /* My apologies to the gods of structured programming. */
  1412. /* Come to this label when you need to resume the inferior.  It's really much
  1413.    cleaner at this time to do a goto than to try and figure out what the
  1414.    if-else chain ought to look like!! */
  1415.  
  1416.     keep_going:
  1417.  
  1418. save_pc:
  1419.       /* Save the pc before execution, to compare with pc after stop.  */
  1420.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  1421.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  1422.                       BREAK is defined, the
  1423.                       original pc would not have
  1424.                       been at the start of a
  1425.                       function. */
  1426.       prev_func_name = stop_func_name;
  1427.       prev_sp = stop_sp;
  1428.  
  1429.       /* If we did not do break;, it means we should keep
  1430.      running the inferior and not return to debugger.  */
  1431.  
  1432.       if (trap_expected && stop_signal != SIGTRAP)
  1433.     {
  1434.       /* We took a signal (which we are supposed to pass through to
  1435.          the inferior, else we'd have done a break above) and we
  1436.          haven't yet gotten our trap.  Simply continue.  */
  1437.       resume ((step_range_end && !step_resume_break_address)
  1438.           || (trap_expected && !step_resume_break_address)
  1439.           || bpstat_should_step (),
  1440.           stop_signal);
  1441.     }
  1442.       else
  1443.     {
  1444.       /* Either the trap was not expected, but we are continuing
  1445.          anyway (the user asked that this signal be passed to the
  1446.          child)
  1447.            -- or --
  1448.          The signal was SIGTRAP, e.g. it was our signal, but we
  1449.          decided we should resume from it.
  1450.  
  1451.          We're going to run this baby now!
  1452.  
  1453.          Insert breakpoints now, unless we are trying
  1454.          to one-proceed past a breakpoint.  */
  1455.       /* If we've just finished a special step resume and we don't
  1456.          want to hit a breakpoint, pull em out.  */
  1457.       if (!step_resume_break_address &&
  1458.           remove_breakpoints_on_following_step)
  1459.         {
  1460.           remove_breakpoints_on_following_step = 0;
  1461.           remove_breakpoints ();
  1462.           breakpoints_inserted = 0;
  1463.         }
  1464.       else if (!breakpoints_inserted &&
  1465.            (step_resume_break_address != 0 || !another_trap))
  1466.         {
  1467.           insert_step_breakpoint ();
  1468.           breakpoints_failed = insert_breakpoints ();
  1469.           if (breakpoints_failed)
  1470.         break;
  1471.           breakpoints_inserted = 1;
  1472.         }
  1473.  
  1474.       trap_expected = another_trap;
  1475.  
  1476.       if (stop_signal == SIGTRAP)
  1477.         stop_signal = 0;
  1478.  
  1479. #ifdef SHIFT_INST_REGS
  1480.       /* I'm not sure when this following segment applies.  I do know, now,
  1481.          that we shouldn't rewrite the regs when we were stopped by a
  1482.          random signal from the inferior process.  */
  1483.  
  1484.           if (!bpstat_explains_signal (stop_bpstat)
  1485.           && (stop_signal != SIGCLD) 
  1486.               && !stopped_by_random_signal)
  1487.             {
  1488.             CORE_ADDR pc_contents = read_register (PC_REGNUM);
  1489.             CORE_ADDR npc_contents = read_register (NPC_REGNUM);
  1490.             if (pc_contents != npc_contents)
  1491.               {
  1492.               write_register (NNPC_REGNUM, npc_contents);
  1493.               write_register (NPC_REGNUM, pc_contents);
  1494.           }
  1495.             }
  1496. #endif /* SHIFT_INST_REGS */
  1497.  
  1498.       resume ((!step_resume_break_address
  1499.            && !handling_longjmp
  1500.            && (step_range_end
  1501.                || trap_expected))
  1502.           || bpstat_should_step (),
  1503.           stop_signal);
  1504.     }
  1505.     }
  1506.  
  1507.  stop_stepping:
  1508.   if (target_has_execution)
  1509.     {
  1510.       /* Assuming the inferior still exists, set these up for next
  1511.      time, just like we did above if we didn't break out of the
  1512.      loop.  */
  1513.       prev_pc = read_pc ();
  1514.       prev_func_start = stop_func_start;
  1515.       prev_func_name = stop_func_name;
  1516.       prev_sp = stop_sp;
  1517.     }
  1518. }
  1519.  
  1520. /* Here to return control to GDB when the inferior stops for real.
  1521.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1522.  
  1523.    STOP_PRINT_FRAME nonzero means print the executing frame
  1524.    (pc, function, args, file, line number and line text).
  1525.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1526.    attempting to insert breakpoints.  */
  1527.  
  1528. void
  1529. normal_stop ()
  1530. {
  1531.   /* Make sure that the current_frame's pc is correct.  This
  1532.      is a correction for setting up the frame info before doing
  1533.      DECR_PC_AFTER_BREAK */
  1534.   if (target_has_execution)
  1535.     (get_current_frame ())->pc = read_pc ();
  1536.   
  1537.   if (breakpoints_failed)
  1538.     {
  1539.       target_terminal_ours_for_output ();
  1540.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1541.       printf ("Stopped; cannot insert breakpoints.\n\
  1542. The same program may be running in another process.\n");
  1543.     }
  1544.  
  1545.   if (target_has_execution)
  1546.     remove_step_breakpoint ();
  1547.  
  1548.   if (target_has_execution && breakpoints_inserted)
  1549.     if (remove_breakpoints ())
  1550.       {
  1551.     target_terminal_ours_for_output ();
  1552.     printf ("Cannot remove breakpoints because program is no longer writable.\n\
  1553. It might be running in another process.\n\
  1554. Further execution is probably impossible.\n");
  1555.       }
  1556.  
  1557.   breakpoints_inserted = 0;
  1558.  
  1559.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1560.      Delete any breakpoint that is to be deleted at the next stop.  */
  1561.  
  1562.   breakpoint_auto_delete (stop_bpstat);
  1563.  
  1564.   /* If an auto-display called a function and that got a signal,
  1565.      delete that auto-display to avoid an infinite recursion.  */
  1566.  
  1567.   if (stopped_by_random_signal)
  1568.     disable_current_display ();
  1569.  
  1570.   if (step_multi && stop_step)
  1571.     return;
  1572.  
  1573.   target_terminal_ours ();
  1574.  
  1575.   if (!target_has_stack)
  1576.     return;
  1577.  
  1578.   /* Select innermost stack frame except on return from a stack dummy routine,
  1579.      or if the program has exited.  Print it without a level number if
  1580.      we have changed functions or hit a breakpoint.  Print source line
  1581.      if we have one.  */
  1582.   if (!stop_stack_dummy)
  1583.     {
  1584.       select_frame (get_current_frame (), 0);
  1585.  
  1586.       if (stop_print_frame)
  1587.     {
  1588.       int source_only;
  1589.  
  1590.       source_only = bpstat_print (stop_bpstat);
  1591.       source_only = source_only ||
  1592.             (   stop_step
  1593.          && step_frame_address == stop_frame_address
  1594.          && step_start_function == find_pc_function (stop_pc));
  1595.  
  1596.           print_stack_frame (selected_frame, -1, source_only? -1: 1);
  1597.  
  1598.       /* Display the auto-display expressions.  */
  1599.       do_displays ();
  1600.     }
  1601.     }
  1602.  
  1603.   /* Save the function value return registers, if we care.
  1604.      We might be about to restore their previous contents.  */
  1605.   if (proceed_to_finish)
  1606.     read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1607.  
  1608.   if (stop_stack_dummy)
  1609.     {
  1610.       /* Pop the empty frame that contains the stack dummy.
  1611.          POP_FRAME ends with a setting of the current frame, so we
  1612.      can use that next. */
  1613.       POP_FRAME;
  1614.       select_frame (get_current_frame (), 0);
  1615.     }
  1616. }
  1617.  
  1618. static void
  1619. insert_step_breakpoint ()
  1620. {
  1621.   if (step_resume_break_address && !step_resume_break_duplicate)
  1622.     target_insert_breakpoint (step_resume_break_address,
  1623.                   step_resume_break_shadow);
  1624. }
  1625.  
  1626. static void
  1627. remove_step_breakpoint ()
  1628. {
  1629.   if (step_resume_break_address && !step_resume_break_duplicate)
  1630.     target_remove_breakpoint (step_resume_break_address,
  1631.                   step_resume_break_shadow);
  1632. }
  1633.  
  1634. int signal_stop_state (signo)
  1635.      int signo;
  1636. {
  1637.   return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0);
  1638. }
  1639.  
  1640. int signal_print_state (signo)
  1641.      int signo;
  1642. {
  1643.   return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0);
  1644. }
  1645.  
  1646. int signal_pass_state (signo)
  1647.      int signo;
  1648. {
  1649.   return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0);
  1650. }
  1651.  
  1652. static void
  1653. sig_print_header ()
  1654. {
  1655.   printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
  1656. }
  1657.  
  1658. static void
  1659. sig_print_info (number)
  1660.      int number;
  1661. {
  1662.   char *abbrev = sig_abbrev(number);
  1663.   if (abbrev == NULL)
  1664.     printf_filtered ("%d\t\t", number);
  1665.   else
  1666.     printf_filtered ("SIG%s (%d)\t", abbrev, number);
  1667.   printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
  1668.   printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
  1669.   printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
  1670.   printf_filtered ("%s\n", sys_siglist[number]);
  1671. }
  1672.  
  1673. /* Specify how various signals in the inferior should be handled.  */
  1674.  
  1675. static void
  1676. handle_command (args, from_tty)
  1677.      char *args;
  1678.      int from_tty;
  1679. {
  1680.   register char *p = args;
  1681.   int signum = 0;
  1682.   register int digits, wordlen;
  1683.   char *nextarg;
  1684.  
  1685.   if (!args)
  1686.     error_no_arg ("signal to handle");
  1687.  
  1688.   while (*p)
  1689.     {
  1690.       /* Find the end of the next word in the args.  */
  1691.       for (wordlen = 0;
  1692.        p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
  1693.        wordlen++);
  1694.       /* Set nextarg to the start of the word after the one we just
  1695.      found, and null-terminate this one.  */
  1696.       if (p[wordlen] == '\0')
  1697.     nextarg = p + wordlen;
  1698.       else
  1699.     {
  1700.       p[wordlen] = '\0';
  1701.       nextarg = p + wordlen + 1;
  1702.     }
  1703.       
  1704.  
  1705.       for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
  1706.  
  1707.       if (signum == 0)
  1708.     {
  1709.       /* It is the first argument--must be the signal to operate on.  */
  1710.       if (digits == wordlen)
  1711.         {
  1712.           /* Numeric.  */
  1713.           signum = atoi (p);
  1714.           if (signum <= 0 || signum >= NSIG)
  1715.         {
  1716.           p[wordlen] = '\0';
  1717.           error ("Invalid signal %s given as argument to \"handle\".", p);
  1718.         }
  1719.         }
  1720.       else
  1721.         {
  1722.           /* Symbolic.  */
  1723.           signum = sig_number (p);
  1724.           if (signum == -1)
  1725.         error ("No such signal \"%s\"", p);
  1726.         }
  1727.  
  1728.       if (signum == SIGTRAP || signum == SIGINT)
  1729.         {
  1730.           if (!query ("SIG%s is used by the debugger.\nAre you sure you want to change it? ", sig_abbrev (signum)))
  1731.         error ("Not confirmed.");
  1732.         }
  1733.     }
  1734.       /* Else, if already got a signal number, look for flag words
  1735.      saying what to do for it.  */
  1736.       else if (!strncmp (p, "stop", wordlen))
  1737.     {
  1738.       signal_stop[signum] = 1;
  1739.       signal_print[signum] = 1;
  1740.     }
  1741.       else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
  1742.     signal_print[signum] = 1;
  1743.       else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
  1744.     signal_program[signum] = 1;
  1745.       else if (!strncmp (p, "ignore", wordlen))
  1746.     signal_program[signum] = 0;
  1747.       else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
  1748.     signal_stop[signum] = 0;
  1749.       else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
  1750.     {
  1751.       signal_print[signum] = 0;
  1752.       signal_stop[signum] = 0;
  1753.     }
  1754.       else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
  1755.     signal_program[signum] = 0;
  1756.       else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
  1757.     signal_program[signum] = 1;
  1758.       /* Not a number and not a recognized flag word => complain.  */
  1759.       else
  1760.     {
  1761.       error ("Unrecognized or ambiguous flag word: \"%s\".", p);
  1762.     }
  1763.  
  1764.       /* Find start of next word.  */
  1765.       p = nextarg;
  1766.       while (*p == ' ' || *p == '\t') p++;
  1767.     }
  1768.  
  1769.   NOTICE_SIGNAL_HANDLING_CHANGE;
  1770.  
  1771.   if (from_tty)
  1772.     {
  1773.       /* Show the results.  */
  1774.       sig_print_header ();
  1775.       sig_print_info (signum);
  1776.     }
  1777. }
  1778.  
  1779. /* Print current contents of the tables set by the handle command.  */
  1780.  
  1781. static void
  1782. signals_info (signum_exp, from_tty)
  1783.      char *signum_exp;
  1784.      int from_tty;
  1785. {
  1786.   register int i;
  1787.   sig_print_header ();
  1788.  
  1789.   if (signum_exp)
  1790.     {
  1791.       /* First see if this is a symbol name.  */
  1792.       i = sig_number (signum_exp);
  1793.       if (i == -1)
  1794.     {
  1795.       /* Nope, maybe it's an address which evaluates to a signal
  1796.          number.  */
  1797.       i = parse_and_eval_address (signum_exp);
  1798.       if (i >= NSIG || i < 0)
  1799.         error ("Signal number out of bounds.");
  1800.     }
  1801.       sig_print_info (i);
  1802.       return;
  1803.     }
  1804.  
  1805.   printf_filtered ("\n");
  1806.   for (i = 0; i < NSIG; i++)
  1807.     {
  1808.       QUIT;
  1809.  
  1810.       sig_print_info (i);
  1811.     }
  1812.  
  1813.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1814. }
  1815.  
  1816. /* Save all of the information associated with the inferior<==>gdb
  1817.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1818.    (defined in inferior.h).  */
  1819.  
  1820. void
  1821. save_inferior_status (inf_status, restore_stack_info)
  1822.      struct inferior_status *inf_status;
  1823.      int restore_stack_info;
  1824. {
  1825.   inf_status->pc_changed = pc_changed;
  1826.   inf_status->stop_signal = stop_signal;
  1827.   inf_status->stop_pc = stop_pc;
  1828.   inf_status->stop_frame_address = stop_frame_address;
  1829.   inf_status->stop_step = stop_step;
  1830.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1831.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1832.   inf_status->trap_expected = trap_expected;
  1833.   inf_status->step_range_start = step_range_start;
  1834.   inf_status->step_range_end = step_range_end;
  1835.   inf_status->step_frame_address = step_frame_address;
  1836.   inf_status->step_over_calls = step_over_calls;
  1837.   inf_status->step_resume_break_address = step_resume_break_address;
  1838.   inf_status->stop_after_trap = stop_after_trap;
  1839.   inf_status->stop_soon_quietly = stop_soon_quietly;
  1840.   /* Save original bpstat chain here; replace it with copy of chain. 
  1841.      If caller's caller is walking the chain, they'll be happier if we
  1842.      hand them back the original chain when restore_i_s is called.  */
  1843.   inf_status->stop_bpstat = stop_bpstat;
  1844.   stop_bpstat = bpstat_copy (stop_bpstat);
  1845.   inf_status->breakpoint_proceeded = breakpoint_proceeded;
  1846.   inf_status->restore_stack_info = restore_stack_info;
  1847.   inf_status->proceed_to_finish = proceed_to_finish;
  1848.   
  1849.   bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1850.   
  1851.   record_selected_frame (&(inf_status->selected_frame_address),
  1852.              &(inf_status->selected_level));
  1853.   return;
  1854. }
  1855.  
  1856. void
  1857. restore_inferior_status (inf_status)
  1858.      struct inferior_status *inf_status;
  1859. {
  1860.   FRAME fid;
  1861.   int level = inf_status->selected_level;
  1862.  
  1863.   pc_changed = inf_status->pc_changed;
  1864.   stop_signal = inf_status->stop_signal;
  1865.   stop_pc = inf_status->stop_pc;
  1866.   stop_frame_address = inf_status->stop_frame_address;
  1867.   stop_step = inf_status->stop_step;
  1868.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1869.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1870.   trap_expected = inf_status->trap_expected;
  1871.   step_range_start = inf_status->step_range_start;
  1872.   step_range_end = inf_status->step_range_end;
  1873.   step_frame_address = inf_status->step_frame_address;
  1874.   step_over_calls = inf_status->step_over_calls;
  1875.   step_resume_break_address = inf_status->step_resume_break_address;
  1876.   stop_after_trap = inf_status->stop_after_trap;
  1877.   stop_soon_quietly = inf_status->stop_soon_quietly;
  1878.   bpstat_clear (&stop_bpstat);
  1879.   stop_bpstat = inf_status->stop_bpstat;
  1880.   breakpoint_proceeded = inf_status->breakpoint_proceeded;
  1881.   proceed_to_finish = inf_status->proceed_to_finish;
  1882.  
  1883.   bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1884.  
  1885.   /* The inferior can be gone if the user types "print exit(0)"
  1886.      (and perhaps other times).  */
  1887.   if (target_has_stack && inf_status->restore_stack_info)
  1888.     {
  1889.       fid = find_relative_frame (get_current_frame (),
  1890.                  &level);
  1891.  
  1892.       /* If inf_status->selected_frame_address is NULL, there was no
  1893.      previously selected frame.  */
  1894.       if (fid == 0 ||
  1895.       FRAME_FP (fid) != inf_status->selected_frame_address ||
  1896.       level != 0)
  1897.     {
  1898. #if 1
  1899.       /* I'm not sure this error message is a good idea.  I have
  1900.          only seen it occur after "Can't continue previously
  1901.          requested operation" (we get called from do_cleanups), in
  1902.          which case it just adds insult to injury (one confusing
  1903.          error message after another.  Besides which, does the
  1904.          user really care if we can't restore the previously
  1905.          selected frame?  */
  1906.       fprintf (stderr, "Unable to restore previously selected frame.\n");
  1907. #endif
  1908.       select_frame (get_current_frame (), 0);
  1909.       return;
  1910.     }
  1911.       
  1912.       select_frame (fid, inf_status->selected_level);
  1913.     }
  1914. }
  1915.  
  1916.  
  1917. void
  1918. _initialize_infrun ()
  1919. {
  1920.   register int i;
  1921.  
  1922.   add_info ("signals", signals_info,
  1923.         "What debugger does when program gets various signals.\n\
  1924. Specify a signal number as argument to print info on that signal only.");
  1925.  
  1926.   add_com ("handle", class_run, handle_command,
  1927.        "Specify how to handle a signal.\n\
  1928. Args are signal number followed by flags.\n\
  1929. Flags allowed are \"stop\", \"print\", \"pass\",\n\
  1930.  \"nostop\", \"noprint\" or \"nopass\".\n\
  1931. Print means print a message if this signal happens.\n\
  1932. Stop means reenter debugger if this signal happens (implies print).\n\
  1933. Pass means let program see this signal; otherwise program doesn't know.\n\
  1934. Pass and Stop may be combined.");
  1935.  
  1936.   for (i = 0; i < NSIG; i++)
  1937.     {
  1938.       signal_stop[i] = 1;
  1939.       signal_print[i] = 1;
  1940.       signal_program[i] = 1;
  1941.     }
  1942.  
  1943.   /* Signals caused by debugger's own actions
  1944.      should not be given to the program afterwards.  */
  1945.   signal_program[SIGTRAP] = 0;
  1946.   signal_program[SIGINT] = 0;
  1947.  
  1948.   /* Signals that are not errors should not normally enter the debugger.  */
  1949. #ifdef SIGALRM
  1950.   signal_stop[SIGALRM] = 0;
  1951.   signal_print[SIGALRM] = 0;
  1952. #endif /* SIGALRM */
  1953. #ifdef SIGVTALRM
  1954.   signal_stop[SIGVTALRM] = 0;
  1955.   signal_print[SIGVTALRM] = 0;
  1956. #endif /* SIGVTALRM */
  1957. #ifdef SIGPROF
  1958.   signal_stop[SIGPROF] = 0;
  1959.   signal_print[SIGPROF] = 0;
  1960. #endif /* SIGPROF */
  1961. #ifdef SIGCHLD
  1962.   signal_stop[SIGCHLD] = 0;
  1963.   signal_print[SIGCHLD] = 0;
  1964. #endif /* SIGCHLD */
  1965. #ifdef SIGCLD
  1966.   signal_stop[SIGCLD] = 0;
  1967.   signal_print[SIGCLD] = 0;
  1968. #endif /* SIGCLD */
  1969. #ifdef SIGIO
  1970.   signal_stop[SIGIO] = 0;
  1971.   signal_print[SIGIO] = 0;
  1972. #endif /* SIGIO */
  1973. #ifdef SIGURG
  1974.   signal_stop[SIGURG] = 0;
  1975.   signal_print[SIGURG] = 0;
  1976. #endif /* SIGURG */
  1977. }
  1978. @
  1979.